<template>
    <div class="menuList">
        <!--背景卡片-->
        <el-card class="box-card">
            <el-form size="mini" ref="souSuoForm" :inline="true" @submit.native.prevent :model="souSuoFormInline" class="demo-form-inline" style="margin-bottom: 0px">
                <el-form-item>
                    <el-button type="primary" @click="displayInsertForm=true" size="mini" icon="el-icon-plus">发布通告</el-button>
                </el-form-item>
                <el-form-item>
                    <el-date-picker
                            v-model="souSuoFormInline.gmtCreate"
                            type="date"
                            placeholder="选择创建日期"
                            size="mini">
                    </el-date-picker>
                    ——
                    <el-date-picker
                            v-model="souSuoFormInline.gmtModified"
                            type="date"
                            placeholder="选择结束日期"
                            size="mini">
                    </el-date-picker>
                </el-form-item>
                <el-form-item>
                    <el-button type="primary" @click="initTable"  icon="el-icon-search">查询</el-button>
                    <el-button @click="resetForm" icon="el-icon-refresh">重置</el-button>
                </el-form-item>
            </el-form>

            <!--数据表格-->
            <el-table
                :data="tableData"
                border
                style="width: 100%;margin-bottom: 20px;"
                row-key="id"
                :default-expand-all="false">
                <el-table-column
                        prop="id"
                        label="编号"
                        align="center"
                        width="150px"
                        >
                </el-table-column>
                <el-table-column
                        prop="gmt_create"
                        align="center"
                        label="创建时间">
                </el-table-column>
                <el-table-column
                        align="center"
                        prop="username"
                        label="发布人">
                </el-table-column>
                <el-table-column
                        align="center"
                        fixed="right"
                        label="操作"
                        width="250px">
                    <template slot-scope="scope">
                        <el-button type="primary" size="mini" @click="query(scope.row.id)">查看通知</el-button>
                        <el-button type="danger" size="mini" @click="del(scope.row.id)">删除</el-button>
                    </template>
                </el-table-column>
            </el-table>
            <el-divider><i class="el-icon-moon-night"></i></el-divider>
            <!--分页栏-->
            <el-pagination
                    @size-change="handleSizeChange"
                    @current-change="handleCurrentChange"
                    style="float: right;margin-top: 20px; margin-bottom: 22px"
                    :current-page="currentPage"
                    :page-sizes="[5, 10, 15]"
                    :page-size="pageSize"
                    layout="total, sizes, prev, pager, next, jumper"
                    :total="total">
            </el-pagination>
            <!-- 新增主目录的弹出层（新增按钮）-->
            <el-dialog
                    title="新增主目录"
                    :visible.sync="displayInsertForm"
                    width="35%">
                <el-form ref="insertForm" :model="insertFormDate" :rules="formRules" label-width="100px">
                    <el-form-item  label="发布内容" prop="msg">
                        <el-input  type="textarea" v-model="insertFormDate.msg" style="width: 300px"></el-input>
                    </el-form-item>
                    <el-form-item label="接收人">
                        <el-select v-model="insertFormDate.bid" placeholder="选择接收人">
                            <el-option v-for="c in client" :label="c.uname" :value="c.uid"></el-option>
                        </el-select>
                    </el-form-item>
                </el-form>

                <el-row style="margin-top:17px;">
                    <el-button style="float:right;margin-left:6px;" size="mini" type="danger" plain @click="displayInsertForm=false">取 消</el-button>
                    <el-button style="float:right" size="mini" type="primary"  @click="insertFormSubmit()">确 定</el-button>
                </el-row>
            </el-dialog>
            <!-- 查看发布内容-->
            <el-dialog
                    title="查看发布内容"
                    :visible.sync="queryCondition"
                    width="35%">
                <el-form :model="queryFormDate"  label-width="80px">
                    <el-form-item  label="发布内容" prop="msg">
                        <el-input  type="textarea" v-model="queryFormDate.msg" style="width:200px"></el-input>
                    </el-form-item>
                </el-form>
                <el-row style="margin-top:17px;">
                    <el-button style="float:right;margin-left:6px;" size="mini" type="danger" plain @click="queryCondition=false">取 消</el-button>
                    <el-button style="float:right" size="mini" type="primary" @click="Checkdetermine()">确 定</el-button>
                </el-row>
            </el-dialog>
        </el-card>
    </div>
</template>

<script>
    import result from "../../../config";

    export default {
        name: "MenuList",
        data(){
            return{
                //接收人
                client:[],
                id:'',
                //查看发布的内容
                queryFormDate:{},
                //查看发布
                queryCondition:false,
                //搜索表单
                souSuoFormInline:{
                },
                //表格数据
                tableData: [],
                //分页信息
                currentPage:1,
                //当前页码数
                pageSize:5,
                //总条数
                total:0,
                //新增表单数据
                displayInsertForm:false,
                insertFormDate:{
                    msg:'',
                },

                //主目录或菜单修改表单的层显示
                displayUpdateForm:false,
                //按钮修改表单的层显示
                anNiuUpdateForm:false,

                //修改权限
                displayUpdatePermission:false,
                ids: [],

                //按钮新增
                DisplayInsertPermission:false,
                ffType:'',

                //表单的规则
                formRules:{
                    msg:[
                        {required:true,message:'请输入内容',trigger:'blur'},
                    ],
                },
            }
        },
        //页面加载时初始化表格数据
        created() {
            this.initTable();
        },
        methods: {
            //重置搜索表单
            resetForm() {
                this.initTable();

            },
            query(id){
                this.queryCondition=true;
                this.id=id;
                this.$http.post("/manage/manage/queryCon/"+this.id).then(result=>{
                    console.log(result)
                    if (result.data.code===2000){
                        this.queryFormDate=result.data.data
                        this.$message.success(result.data.msg)
                        this.initTable();
                    }
                })
            },
            //查看发布
            Checkdetermine(){
                this.initTable();
                this.queryCondition=false;
            },
            //页头的点击条状
            goBack(){
              this.$router.push("/houHome")
            },

            //获取表格数据
            initTable() {
                this.$http.post("/manage/manage/selectAll/"+this.currentPage+"/"+this.pageSize,this.souSuoFormInline).then(result=>{
                    if (result.data.code === 2000) {
                        console.log(result)
                        this.tableData = result.data.data.ipage.records;
                        this.total = result.data.data.ipage.total;
                        this.client=result.data.data.allClientNameAndId;
                        this.souSuoFormInline={}
                    }
                })
            },
            //页数改变时
            handleCurrentChange(val) {
                this.currentPage = val;
                this.initTable();
            },
            //每页数量发生改变时
            handleSizeChange(val) {
                this.pageSize = val;
                this.initTable();
            },

            del(id){
                this.$confirm(`确定要《《彻底删除》》该用户吗?`, {
                    confirmButtonText: '确定',
                    cancelButtonText: '取消',
                    type: 'warning'
                }).then(() => {
                    this.$http.post("/manage/manage/deleteById/"+id).then(result=>{
                        if (result.data.code===2000){
                            this.$message.success(result.data.msg);
                            this.initTable()
                        }else {
                            this.$message.error(result.data.msg);
                            this.initTable();
                        }
                    })
                }).catch(() => {
                    this.$message({
                        type: 'info',
                        message: '删除已取消'
                    });
                })

            },
            //新增表单提交
            insertFormSubmit(){
                this.$refs.insertForm.validate(valid => {
                    if (valid){
                        this.$http.post(`/manage/manage/insert`,this.insertFormDate).then(result=>{
                            console.log(result)
                            if (result.data.code===2000){
                                this.initTable();
                                this.$message.success(result.data.msg);
                                this.displayInsertForm=false;
                            }else {
                                this.$message.error("添加失败");
                            }
                        })
                    }
                })
            },
        }
    }
</script>
